﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Native.XQ.SDK.Event.EventArgs;
using Native.XQ.SDK.Interfaces;

namespace Drawastick.Code
{
    public class Event_AppEnable : IXQAppEnable
    {
        public void AppEnable(object sender, XQEventArgs e)
        {
            if (!File.Exists(e.XQAPI.AppDirectory + "签.ini"))
            {
                //没签？
                Task.Factory.StartNew(async()=> {
                    e.XQAPI.Log("联网获取抽签数据...");
                    var str = await new HttpClient().GetAsync("https://gitee.com/heerkaisair/Draw-A-Stick/raw/master/%E7%AD%BE.ini");
                    File.Create(e.XQAPI.AppDirectory + "签.ini").Close();
                    File.WriteAllText(e.XQAPI.AppDirectory + "签.ini", await str.Content.ReadAsStringAsync());

                    e.XQAPI.Log("写入 签.ini 成功 √");

                });
            }
        }
    }
}
